import cookies from "./util.cookies";
import verify from "./util.verify";
import store from "./util.store";
import route from "@/router";
// import vueStore from "@/store/index";
// console.log(vueStore);

const util = {
  cookies,
  verify,
  store,
  open: function (url, target = "_self") {
    var a = document.createElement("a");
    a.setAttribute("href", url);
    a.setAttribute("target", target);
    a.setAttribute("id", "shop-link-temp");
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(document.getElementById("d2admin-link-temp"));
  },
  /**
   * @description 打开新页面
   * @param {String} url 地址
   */
  toLogin: (type) => {
    if (type === 1) {
      if (route.history.current.name !== "Register")
        route.replace("/login/register");
      return;
    }
    let current;
    try {
      if (route.history.current.name === "Login") return;
      current = route.history.current.fullPath;
    } catch (err) {
      current = "/home";
    }

    store.setItem("login-redirect", current);
    route.push("/login");
  },
  showLoading: () => {
    let vueStore = require("@/store").default;
    vueStore.commit("loading/showLoading");
  },
  hideLoading: () => {
    let vueStore = require("@/store").default;
    vueStore.commit("loading/hideLoading");
  },
};

export default util;
